package com.koron.css2.serviceManage.service;

import com.koron.css2.ApplicationConfig;
import com.koron.css2.serviceManage.mapper.QuartzMapper;
import com.koron.css2.serviceManage.mapper.TWaterCompanyMapper;
import com.koron.util.Tools;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class CompanyService {
	private static Logger log = LogManager.getLogger(CompanyService.class);
	
	/**
	 * 获取水司信息
	 * 
	 * @param sessionFactory
	 * @return
	 */
	@TaskAnnotation("selectCompany")
	public List<String> selectCompany(SessionFactory sessionFactory) {
		List<String> companyList;
		try {
			TWaterCompanyMapper mapper = sessionFactory.getMapper(TWaterCompanyMapper.class, "_default");
			companyList = mapper.selectCompany(ApplicationConfig.getWaterCodeFilter());
		} catch (Exception e) {
			log.error("查询水司编号失败", e);
			throw new RuntimeException(e.getMessage());
		}
		return companyList;
	}

	/**
	 * 更新定时任务 执行结束时间
	 */
	@TaskAnnotation("updateExecutionTime")
	public void updateExecutionTime(SessionFactory sessionFactory,String jobName,String jobGroup) {
		try {
			QuartzMapper mapper = sessionFactory.getMapper(QuartzMapper.class, "_default");
			//更新任务最后执行时间
			String time = Tools.getCurrentTime();
			mapper.updateExecutionTime(ApplicationConfig.getQuartzPrefix(),time,jobName,jobGroup);
		} catch (Exception e) {
			log.error("更新任务执行结束时间失败", e);
			throw new RuntimeException(e.getMessage());
		}
		return ;
	}
}
